package com.ibr.ticketmanagement.app.data;

import android.content.ContentValues;
import android.content.Context;

import com.ibr.ticketmanagement.app.util.DatabaseHandler;
import com.ibr.ticketmanagement.app.util.Utility;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Girishn on 08-05-2014.
 */
public class FEReport {

    int _id;
    private int ticketId;
    private int actionPlanId;
    private int fieldEngineerId;
    private String workWindow;
    private String timeStart;
    private String timeFinished;
    private boolean sent = false;
    private String work_done_value;
    private boolean billable_value;
    private boolean closed_value;
    private String hours_value;
    private String miles_value;
    private int numberPicker_01_value;
    private String part_01_value;
    private String location_01_value;
    private int numberPicker_02_value;
    private String part_02_value;
    private String location_02_value;
    private int numberPicker_03_value;
    private String part_03_value;
    private String location_03_value;
    private int numberPicker_04_value;
    private String part_04_value;
    private String location_04_value;

    public FEReport(int _id, int ticketId, int actionPlanId, int fieldEngineerId, String workWindow, String timeStart, String timeFinished,
                    String work_done_value, boolean billable_value, boolean closed_value, String hours_value,
                    String miles_value, int numberPicker_01_value, String part_01_value, String location_01_value, int numberPicker_02_value,
                    String part_02_value, String location_02_value, int numberPicker_03_value, String part_03_value, String location_03_value,
                    int numberPicker_04_value, String part_04_value, String location_04_value, boolean sent) {
        this._id = _id;
        this.ticketId = ticketId;
        this.actionPlanId = actionPlanId;
        this.fieldEngineerId = fieldEngineerId;
        this.workWindow = workWindow;
        this.timeStart = timeStart;
        this.timeFinished = timeFinished;
        this.work_done_value = work_done_value;
        this.billable_value = billable_value;
        this.closed_value = closed_value;
        this.hours_value = hours_value;
        this.miles_value = miles_value;
        this.numberPicker_01_value = numberPicker_01_value;
        this.part_01_value = part_01_value;
        this.location_01_value = location_01_value;
        this.numberPicker_02_value = numberPicker_02_value;
        this.part_02_value = part_02_value;
        this.location_02_value = location_02_value;
        this.numberPicker_03_value = numberPicker_03_value;
        this.part_03_value = part_03_value;
        this.location_03_value = location_03_value;
        this.numberPicker_04_value = numberPicker_04_value;
        this.part_04_value = part_04_value;
        this.location_04_value = location_04_value;
        this.sent = sent;
    }

    public FEReport(int ticketId, int actionPlanId, int fieldEngineerId, String workWindow, String timeStart, String timeFinished) {
        this.ticketId = ticketId;
        this.actionPlanId = actionPlanId;
        this.fieldEngineerId = fieldEngineerId;
        this.workWindow = workWindow;
        this.timeStart = timeStart;
        this.timeFinished = timeFinished;
        this.sent = false;
    }

    public FEReport(int ticketId, int actionPlan_id, int field_engineer_id, String workWindow, String timeStart, String timeFinished,
                    String work_done_value, boolean billable_value, boolean closed_value, String hours_value,
                    String miles_value, int numberPicker_01_value, String part_01_value, String location_01_value, int numberPicker_02_value,
                    String part_02_value, String location_02_value, int numberPicker_03_value, String part_03_value, String location_03_value,
                    int numberPicker_04_value, String part_04_value, String location_04_value) {
        this.ticketId = ticketId;
        this.actionPlanId = actionPlan_id;
        this.fieldEngineerId = field_engineer_id;
        this.workWindow = workWindow;
        this.timeStart = timeStart;
        this.timeFinished = timeFinished;
        this.work_done_value = work_done_value;
        this.billable_value = billable_value;
        this.closed_value = closed_value;
        this.hours_value = hours_value;
        this.miles_value = miles_value;
        this.numberPicker_01_value = numberPicker_01_value;
        this.part_01_value = part_01_value;
        this.location_01_value = location_01_value;
        this.numberPicker_02_value = numberPicker_02_value;
        this.part_02_value = part_02_value;
        this.location_02_value = location_02_value;
        this.numberPicker_03_value = numberPicker_03_value;
        this.part_03_value = part_03_value;
        this.location_03_value = location_03_value;
        this.numberPicker_04_value = numberPicker_04_value;
        this.part_04_value = part_04_value;
        this.location_04_value = location_04_value;
        this.sent = false;
    }

    public String getWork_done_value() {
        return work_done_value;
    }

    public void setWork_done_value(String work_done_value) {
        this.work_done_value = work_done_value;
    }

    public boolean isBillable_value() {
        return billable_value;
    }

    public void setBillable_value(boolean billable_value) {
        this.billable_value = billable_value;
    }

    public boolean isClosed_value() {
        return closed_value;
    }

    public void setClosed_value(boolean closed_value) {
        this.closed_value = closed_value;
    }

    public String getHours_value() {
        return hours_value;
    }

    public void setHours_value(String hours_value) {
        this.hours_value = hours_value;
    }

    public String getMiles_value() {
        return miles_value;
    }

    public void setMiles_value(String miles_value) {
        this.miles_value = miles_value;
    }

    public int getNumberPicker_01_value() {
        return numberPicker_01_value;
    }

    public void setNumberPicker_01_value(int numberPicker_01_value) {
        this.numberPicker_01_value = numberPicker_01_value;
    }

    public String getPart_01_value() {
        return part_01_value;
    }

    public void setPart_01_value(String part_01_value) {
        this.part_01_value = part_01_value;
    }

    public String getLocation_01_value() {
        return location_01_value;
    }

    public void setLocation_01_value(String location_01_value) {
        this.location_01_value = location_01_value;
    }

    public int getNumberPicker_02_value() {
        return numberPicker_02_value;
    }

    public void setNumberPicker_02_value(int numberPicker_02_value) {
        this.numberPicker_02_value = numberPicker_02_value;
    }

    public String getPart_02_value() {
        return part_02_value;
    }

    public void setPart_02_value(String part_02_value) {
        this.part_02_value = part_02_value;
    }

    public String getLocation_02_value() {
        return location_02_value;
    }

    public void setLocation_02_value(String location_02_value) {
        this.location_02_value = location_02_value;
    }

    public int getNumberPicker_03_value() {
        return numberPicker_03_value;
    }

    public void setNumberPicker_03_value(int numberPicker_03_value) {
        this.numberPicker_03_value = numberPicker_03_value;
    }

    public String getPart_03_value() {
        return part_03_value;
    }

    public void setPart_03_value(String part_03_value) {
        this.part_03_value = part_03_value;
    }

    public String getLocation_03_value() {
        return location_03_value;
    }

    public void setLocation_03_value(String location_03_value) {
        this.location_03_value = location_03_value;
    }

    public int getNumberPicker_04_value() {
        return numberPicker_04_value;
    }

    public void setNumberPicker_04_value(int numberPicker_04_value) {
        this.numberPicker_04_value = numberPicker_04_value;
    }

    public String getPart_04_value() {
        return part_04_value;
    }

    public void setPart_04_value(String part_04_value) {
        this.part_04_value = part_04_value;
    }

    public String getLocation_04_value() {
        return location_04_value;
    }

    public void setLocation_04_value(String location_04_value) {
        this.location_04_value = location_04_value;
    }

    public int get_id() {
        return _id;
    }

    public void set_id(int _id) {
        this._id = _id;
    }

    public int getTicketId() {
        return ticketId;
    }

    public void setTicketId(int ticketId) {
        this.ticketId = ticketId;
    }

    public int getActionPlanId() {
        return actionPlanId;
    }

    public void setActionPlanId(int actionPlanId) {
        this.actionPlanId = actionPlanId;
    }

    public void setActionPlan(int actionPlanId) {
        this.actionPlanId = actionPlanId;
    }

    public int getFieldEngineerId() {
        return fieldEngineerId;
    }

    public void setFieldEngineerId(int fieldEngineerId) {
        this.fieldEngineerId = fieldEngineerId;
    }

    public String getWorkWindow() {
        return workWindow;
    }

    public void setWorkWindow(String workWindow) {
        this.workWindow = workWindow;
    }

    public String getTimeStart() {
        return timeStart;
    }

    public void setTimeStart(String timeStart) {
        this.timeStart = timeStart;
    }

    public String getTimeFinished() {
        return timeFinished;
    }

    public void setTimeFinished(String timeFinished) {
        this.timeFinished = timeFinished;
    }

    public boolean isSent() {
        return sent;
    }

    public void setSent(boolean sent) {
        this.sent = sent;
    }

    public ContentValues getContentValues() {
        ContentValues values = new ContentValues();
        values.put(DatabaseHandler.KEY_FE_TICKET_ID, String.valueOf(getTicketId()));
        values.put(DatabaseHandler.KEY_FE_ACTION_PLAN, String.valueOf(getActionPlanId()));
        values.put(DatabaseHandler.KEY_FE_FIELD_ENGINEER_ID, String.valueOf(getFieldEngineerId()));
        values.put(DatabaseHandler.KEY_FE_WORK_WINDOW, getWorkWindow());
        values.put(DatabaseHandler.KEY_FE_TIME_START, getTimeStart());
        values.put(DatabaseHandler.KEY_FE_TIME_FINISHED, getTimeFinished());
        values.put(DatabaseHandler.KEY_FE_WORK_DONE, getWork_done_value());
        values.put(DatabaseHandler.KEY_FE_BILLABLE, String.valueOf(isBillable_value()));
        values.put(DatabaseHandler.KEY_FE_CLOSED, String.valueOf(isClosed_value()));
        values.put(DatabaseHandler.KEY_FE_TIME_TRAVEL, getHours_value());
        values.put(DatabaseHandler.KEY_FE_MILES, getMiles_value());
        values.put(DatabaseHandler.KEY_FE_NUMBER_01, getNumberPicker_01_value());
        values.put(DatabaseHandler.KEY_FE_PART_01, getPart_01_value());
        values.put(DatabaseHandler.KEY_FE_LOCATION_01, getLocation_01_value());
        values.put(DatabaseHandler.KEY_FE_NUMBER_02, getNumberPicker_02_value());
        values.put(DatabaseHandler.KEY_FE_PART_02, getPart_02_value());
        values.put(DatabaseHandler.KEY_FE_LOCATION_02, getLocation_02_value());
        values.put(DatabaseHandler.KEY_FE_PART_03, getPart_03_value());
        values.put(DatabaseHandler.KEY_FE_LOCATION_03, getLocation_03_value());
        values.put(DatabaseHandler.KEY_FE_NUMBER_03, getNumberPicker_03_value());
        values.put(DatabaseHandler.KEY_FE_NUMBER_04, getNumberPicker_04_value());
        values.put(DatabaseHandler.KEY_FE_PART_04, getPart_04_value());
        values.put(DatabaseHandler.KEY_FE_LOCATION_04, getLocation_04_value());
        values.put(DatabaseHandler.KEY_FE_SENT, String.valueOf(isSent()));
        return values;
    }

    public List<NameValuePair> createNameValuePairs(Context context) {
        List<NameValuePair> params = new ArrayList<NameValuePair>();
        params.add(new BasicNameValuePair("ticketId", String.valueOf(getTicketId())));
        params.add(new BasicNameValuePair("actionPlanId", String.valueOf(getActionPlanId())));
        params.add(new BasicNameValuePair("fieldEngineerId", String.valueOf(getFieldEngineerId())));
        params.add(new BasicNameValuePair("workWindow", getWorkWindow()));
        params.add(new BasicNameValuePair("timeStart", getTimeStart()));
        params.add(new BasicNameValuePair("timeFinished", getTimeFinished()));
        params.add(new BasicNameValuePair("work_done_value", getWork_done_value()));
        params.add(new BasicNameValuePair("billable_value", isBillable_value() ? "1" : "0"));
        params.add(new BasicNameValuePair("closed_value", String.valueOf(isClosed_value())));
        params.add(new BasicNameValuePair("travelTime", getHours_value()));
        params.add(new BasicNameValuePair("miles", getMiles_value()));
        params.add(new BasicNameValuePair("parts[0][number]", String.valueOf(getNumberPicker_01_value())));
        params.add(new BasicNameValuePair("parts[0][part]", Utility.getPart(context, getPart_01_value())));
        params.add(new BasicNameValuePair("parts[0][location]", Utility.getLocation(context, getLocation_01_value())));
        params.add(new BasicNameValuePair("parts[1][number]", String.valueOf(getNumberPicker_02_value())));
        params.add(new BasicNameValuePair("parts[1][part]", Utility.getPart(context, getPart_02_value())));
        params.add(new BasicNameValuePair("parts[1][location]", Utility.getLocation(context, getLocation_02_value())));
        params.add(new BasicNameValuePair("parts[2][part]", Utility.getPart(context, getPart_03_value())));
        params.add(new BasicNameValuePair("parts[2][location]", Utility.getLocation(context, getLocation_03_value())));
        params.add(new BasicNameValuePair("parts[2][number]", String.valueOf(getNumberPicker_03_value())));
        params.add(new BasicNameValuePair("parts[3][number]", String.valueOf(getNumberPicker_04_value())));
        params.add(new BasicNameValuePair("parts[3][part]", Utility.getPart(context, getPart_04_value())));
        params.add(new BasicNameValuePair("parts[3][location]", Utility.getLocation(context, getLocation_04_value())));
        return params;
    }
}